const koa = require("koa");
const staticCache = require("koa-static-cache");
const convert = require("koa-convert");
const session = require("koa-session");
const betterBody = require("koa-better-body");
const ejs = require("koa-ejs");
const router = require("koa-router");
const db=require("./libs/db")
const error=require('./libs/error_handler');
const loglib=require('./libs/log');
const conf = require("./config");



//server
let server = new koa();
server.listen(conf.port);

//mysql
server.use(db);

//错误处理
error(server);
loglib(server);

//post
server.use(convert(betterBody({
    uploadDir:conf.uploadDir,
})));

//session
server.keys=conf.secret_key;
server.use(session({}, server));

//路由
let mainr = router();
//主入口 //子模块
mainr.use("/",require('./routers/index'));
// mainr.use("/sys",require('./routers/sys'));
// mainr.use("/home",require('./routers/home'));
server.use(mainr.routes());

//static
server.use(staticCache(conf.wwwDir,{gzip:true}))

